home *** CD-ROM | disk | FTP | other *** search
- /* Copyright (c) Mark J. Kilgard, 1994, 1996. */
-
- /* This program is freely distributable without licensing fees
- and is provided without guarantee or warrantee expressed or
- implied. This program is -not- in the public domain. */
-
- #include <stdlib.h>
- #include "gl.h"
- #include "agl.h"
- #include "glut.h"
- #include "glutint.h"
-
- GLUTcolormap *__glutColormapList = NULL;
-
- extern GLUTwindow *__glutCurrentWindow;
- extern GLUTwindow **__glutWindowList;
-
- #define CLAMP(i) ((i) > 1.0 ? 1.0 : ((i) < 0.0 ? 0.0 : (i)))
-
- void glutSetColor(int ndx, GLfloat red, GLfloat green, GLfloat blue)
- {
- GLint tab[4];
-
- if(!__glutCurrentWindow || !__glutCurrentWindow->win)
- {
- __glutWarning("glutSetColor: no active window");
- return;
- }
-
- if(ndx < 0 || ndx > 255) return;
-
- tab[0] = ndx;
- tab[1] = (GLushort) (CLAMP(red) * 65535.0f);
- tab[2] = (GLushort) (CLAMP(green) * 65535.0f);
- tab[3] = (GLushort) (CLAMP(blue) * 65535.0f);
-
- aglSetInteger(__glutCurrentWindow->ctx, AGL_COLORMAP_ENTRY, tab);
- }
-
- GLfloat glutGetColor(int ndx, int component)
- {
- GLint tab[4];
- GLfloat color;
-
- if(!__glutCurrentWindow || !__glutCurrentWindow->win)
- {
- __glutWarning("glutGetColor: no active window");
- return 0.0;
- }
-
- if(ndx < 0 || ndx > 255) return 0.0;
-
- tab[0] = ndx;
-
- aglGetInteger(__glutCurrentWindow->ctx, AGL_COLORMAP_ENTRY, tab);
-
- switch(component)
- {
- case 0:
- color = (GLfloat) tab[1] / 65535.0f;
- break;
- case 1:
- color = (GLfloat) tab[2] / 65535.0f;
- break;
- default: /* case 2: */
- color = (GLfloat) tab[3] / 65535.0f;
- break;
- }
-
- return color;
- }
-
- void glutCopyColormap(int winnum)
- {
- GLint tab[4], i;
- GLUTwindow *dst_win;
-
- if(!__glutCurrentWindow || !__glutCurrentWindow->win)
- {
- __glutWarning("glutCopyColormap: no active window");
- return;
- }
-
- if(winnum < 1 || winnum > __glutWindowListSize)
- {
- __glutWarning("glutCopyColormap attempted on bogus window.");
- return;
- }
-
- dst_win = __glutWindowList[winnum - 1];
- if(!dst_win)
- {
- __glutWarning("glutCopyColormap attempted on bogus window.");
- return;
- }
-
- for(i = 0; i < 256; i++)
- {
- tab[i] = i;
-
- aglGetInteger(__glutCurrentWindow->ctx, AGL_COLORMAP_ENTRY, tab);
- aglSetInteger(dst_win->ctx, AGL_COLORMAP_ENTRY, tab);
- }
- }
-